#ifndef PROGSERV_H
#define PROGSERV_H

#include "serv.h"
#include "progsql.h"

/**
 * @todo  This whole inheritance model needs to be revisited.  It seems
 * backwards.
 */

#define PROGRESSIVE_BETS_TO_TRACK 100


struct BetInfo
{
    int32 betTime;  //amount of time between last bet and this one, in milliseconds
    int32 amtPutInJackpot;  // # of cents from this bet placed in jackpot.
};

typedef struct ProgInfo
{
    bool8 progressiveOn;
    int32 jackpotID;
	int32 fixedAmountMultiplier;
    int32 numRealBets, numFunBets;
    BetInfo realBets[PROGRESSIVE_BETS_TO_TRACK];
    BetInfo funBets[PROGRESSIVE_BETS_TO_TRACK];   
    int32 realBetIndex, funBetIndex;
    int32 lastRealBetTime, lastFunBetTime;
    struct ProgInfo *next;
    struct ProgInfo *prev;
} PROGINFO_T, *PPROGINFO_T;


class ProgressiveServer : public Server
{
	public:
		ProgressiveServer(int port,const String& sAppName);
		~ProgressiveServer();

        bool8 isProgressiveOn(int32 jackpotID);
        int32 getProgressiveJackpot(int32 jackpotID, bool8 forReal);

        // kharmon.  10-05-05.  #5861.  Added bPercentage parameter so that a payrate of less than 100 can 
        // optionally be treated as an absolute amount.
		bool8 setProgressiveWinner(int32 jackpotID, int32 payrate, bool8 forReal, int32 progressiveFixedAmountMultiplier, int32* pPayout, int32* multiBankPayout, bool bPercentage = true); 

		bool8 placeProgressiveBet(int32 jackpotID, int32 nContributionAmount, int32 betAmount, int32 betMultiplier, bool8 forReal, int32 progressiveFixedAmountMultiplier, int32& multiBankBet);
        void setProgressiveOn(int32 jackpotID, bool8 progressiveOn);
        void setProgressiveJackpotID(int32 jackpotID);
        bool8 loadJackpot(int32 jackpotID, bool8 forReal, int32 fixedAmountMultiplier);
		bool8 gameEnabled(int32 jackpotID);

    private:

        //these three functions must be defined in the game code, because they require the use of the
        //ProgressiveTrackSQL object
        bool8 jackpotAdjust(int32 jackpotID, int32 jackpotAdjust, int32& jackpot, bool8 forReal, int32 progressiveFixedAmountMultiplier, int32& multiBankPayout);
        bool8 jackpotAdjustByPercent(int32 jackpotID, int32 jackpotAdjust, int32& jackpot, bool8 forReal, int32 progressiveFixedAmountMultiplier, int32& multiBankPayout);
        bool8 jackpotAdjustByBet(int32 jackpotID, int32 betAmount, int32 multiplier, int32& jackpot, int32& increasedAmount, int32& multiBankBet, bool8 forReal, int32 progressiveFixedAmountMultiplier);

        PPROGINFO_T pProgInfoList;  // The single linked list of progressive info's
        
        PPROGINFO_T getProgInfo(int32 jackpotID);
        PPROGINFO_T findProgInfo(int32 jackpotID);
        PPROGINFO_T insertProgInfo(int32 jackpotID);

        void delProgInfoList();
};

extern ProgressiveTrackSQL* tracker;

#endif
